﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<%@ Import Namespace="vuonthieunhi.Areas.Administration.Models" %>
<script src="/Content/ckeditor/ckeditor.js" type="text/javascript"></script>
<%
    CategoryDao catDao = new CategoryDao();
    DistrictDao distDao = new DistrictDao();
    ProvinceDao proDao = new ProvinceDao();
    Partner partner = (Partner)ViewData.Model;    
%>
<script type="text/javascript">
    $(document).ready(function () {
        CKEDITOR.replace('Description', {
            filebrowserImageUploadUrl: '/Administration/Common/UploadImage',
            filebrowserFlashUploadUrl: '/Administration/Common/UploadFlash',
            entities: false
        });
        $("#PartnerForm").validate({
            debug: false,
            errorElement: "span",
            errorPlacement: function (error, element) {
                error.tooltip({
                    bodyHandler: function () {
                        return error.html();
                    }
                });
                error.insertAfter(element);
            },
            rules: {
                PartnerName: {
                    required: true
                },
                CategoryID: {
                    required: true
                },
                Status: {
                    required: true
                },
                Email: {
                    email: true
                },
                OldPrice: {
                    number: true
                },
                CurrentPrice: {
                    number: true
                }
            }
        });
        $("#btnChangeLogo").click(function () {
            var url = "/Administration/Common/UploadImage?controller=Logo&recordID=" + $('#RecordID').val() + "&saveTo=<%=Constants.PHOTO_PATH_ROOT_PARTNER %>&width=100&height=100";
            JS_LIB.popUpWindow(url, '#Logo', 'Upload Hình');
            return false;
        });
        $("#btnChangeBigImage").click(function () {
            var url = "/Administration/Common/UploadImage?controller=BigImage&recordID=" + $('#RecordID').val() + "&saveTo=<%=Constants.PHOTO_PATH_ROOT_PARTNER %>&width=100&height=100";
            JS_LIB.popUpWindow(url, '#BigImages', 'Upload Hình');
            return false;
        });
    });
    var index = 1;
    function AddRow() {
        var rowCount = $('#tblAddress tr').length;
        index = rowCount - 1;
        index++;
        $("#hidValue").val(index);
        $("#tblAddress").append(
            "<tr><td style='width:150px'>" +
                   "<input maxlength='200' style='width: 200px' type='text' name='Street" + index + "' id='Street" + index + "'/>" +
                "</td>" +
                "<td style='width:150px'>" +
                    "<select style='width: 150px;' name='Province" + index + "' id='Province" + index + "' onchange = 'changeProvince(" + index + ")'></select>" +
                "</td>" +
                "<td style='width:150px'>" +
                    "<select style='width: 150px;' name='District" + index + "' id='District" + index + "'></select>" +
                "</td>" +
                 "<td style='width: 150px'>" +
                    "<input type='text' value='' style='width: 150px;' name='Phone" + index + "' maxlength='20' id='Phone" + index + "'>" +
                 "</td>" +
                "<td style='width: 50px;text-align:center'>" +
                       "<input type='radio' value='Address" + index + "' name='MainAddress' id='MainAddress'>" +
                 "</td>" +
                "</tr>");
        //$('#District1 option').clone().appendTo('#District' + index);
    }
    function RemoveRow() {
        if (index > 1) {
            index--;
            $("#tblAddress tr:last").remove();
            $("#hidValue").val(index);
        }
    }
</script>
<table width="85%" border="0" cellpadding="0" cellspacing="0" class="edit">
    <tr>
        <td class="label">
            Hình Ảnh Nhỏ
        </td>
        <td class="input">
            <table>
                <tr>
                    <td>
                        <%
                            string labelPhoto = "<img src='/Content/Images/Common/nopic.gif' height='100px' width='100px' />";
                            if (ViewData.Model == null)
                            {
                                Response.Write("<div id='spanPhoto'>" + labelPhoto + "</div>");
                            }
                            else
                            {
                                    labelPhoto = "<img id='imgLogo' src='" + Constants.PHOTO_PATH_ROOT_PARTNER + partner.Logo
                                                    + "'  height='100px' width='100px' /></a>";
                                    Response.Write("<div id='spanLogo'>" + labelPhoto + "</div>");
                            }
                            if (ViewData.Model == null)
                            {
                                Response.Write(Html.Hidden("RecordID", ""));
                                Response.Write(Html.Hidden("Logo", ""));
                                Response.Write(Html.Hidden("hidValue", 1));
                            }
                            else
                            {
                                Response.Write(Html.Hidden("RecordID", partner.ID));
                                Response.Write(Html.Hidden("ID", partner.ID));
                                Response.Write(Html.Hidden("Logo", partner.Logo));
                            }                            
                        %>
                    </td>
                    <td valign="top">
                        <input type="button" class="upload_image" id="btnChangeLogo" value="" title="Đổi Logo" />
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td class="label">
            Hình Ảnh Lớn
        </td>
        <td class="input">
            <table>
                <tr>
                    <td>
                        <%
                            string labelBigPhoto = "<img src='/Content/Images/Common/nopic.gif' height='100px' width='100px' />";
                            if (ViewData.Model == null)
                            {
                                Response.Write("<div id='spanBigImages'>" + labelPhoto + "</div>");
                            }
                            else
                            {
                                    labelPhoto = "<img id='imgBigImages' src='" + Constants.PHOTO_PATH_ROOT_PARTNER + partner.BigImages
                                                    + "' height='100px' width='100px' /></a>";
                                    Response.Write("<div id='spanBigImages'>" + labelPhoto + "</div>");
                            }
                            if (ViewData.Model == null)
                            {
                                Response.Write(Html.Hidden("RecordID", ""));
                                Response.Write(Html.Hidden("BigImages", ""));
                                Response.Write(Html.Hidden("hidValue", 1));
                            }
                            else
                            {
                                Response.Write(Html.Hidden("RecordID", partner.ID));
                                Response.Write(Html.Hidden("ID", partner.ID));
                                Response.Write(Html.Hidden("BigImages", partner.BigImages));
                            }                            
                        %>
                    </td>
                    <td valign="top">
                        <input type="button" class="upload_image" id="btnChangeBigImage" value="" title="Đổi Logo" />
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Tên Sản Phẩm <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("PartnerName", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("PartnerName", partner.PartnerName, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Chọn Danh Mục <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.DropDownList(CommonDataKey.CATEGORY, ViewData[CommonDataKey.CATEGORY] as SelectList, Constants.CATEGORY_FIRST_ITEM, new { @style = "width:180px" }));
                }
                else
                {
                    Response.Write(Html.DropDownList(CommonDataKey.CATEGORY, null, Constants.CATEGORY_FIRST_ITEM, new { @style = "width:180px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Thứ tự hiển thị <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("PartnerOrder", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("PartnerOrder", partner.PartnerOrder, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Giá cũ
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("OldPrice", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("OldPrice", partner.OldPrice, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Giá hiện tại
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("CurrentPrice", string.Empty, new { @maxlength = "20", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("CurrentPrice", partner.CurrentPrice, new { @maxlength = "20", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Lượt xem
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("Views", string.Empty, new { @maxlength = "20", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("Views", partner.Views, new { @maxlength = "20", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Tình trạng
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("Status", string.Empty, new { @maxlength = "20", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("Status", partner.Status, new { @maxlength = "20", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Mã hàng
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("CodeID", string.Empty, new { @maxlength = "20", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("CodeID", partner.CodeID, new { @maxlength = "20", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Kho
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("Store", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("Store", partner.Store, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label">
            Alias
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("Alias", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("Alias", partner.Alias, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Hàng bán chạy <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.CheckBox("IsHotSales", false, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.CheckBox("IsHotSales", partner.IsHotSales, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Hàng mới <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.CheckBox("IsNew", false, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.CheckBox("IsNew", partner.IsNew, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Chọn nhà sản xuất <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.DropDownList("ManufacturerID", null, Constants.CATEGORY_FIRST_ITEM, new { @style = "width:180px" }));
                }
                else
                {
                    Response.Write(Html.DropDownList("ManufacturerID", null, Constants.CATEGORY_FIRST_ITEM, new { @style = "width:180px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Độ tuổi <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("Age", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("Age", partner.Age, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Kích thước <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("Dimension", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("Dimension", partner.Dimension, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Màu sắc <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("Color", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("Color", partner.Color, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Tên phụ <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("SubName", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Response.Write(Html.TextBox("SubName", partner.SubName, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label required">
            Số lượng <span>*</span>
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextBox("Quality", string.Empty, new { @maxlength = "200", @style = "width:200px" }));
                }
                else
                {
                    Stock objStockView = new StockDao().GetByID(partner.ID);
                    Response.Write(Html.TextBox("Quality", objStockView != null? partner.Stock.Quality:0, new { @maxlength = "200", @style = "width:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td class="label" style="vertical-align: top">
            Giới Thiệu
        </td>
        <td class="input">
            <%                
                if (ViewData.Model == null)
                {
                    Response.Write(Html.TextArea("Description", string.Empty, new { @style = "width:600px;height:200px" }));
                }
                else
                {
                    Response.Write(Html.TextArea("Description", Constants.SetHtmlForCKEditor(partner.Description), new { @style = "width:600px;height:200px" }));
                }                
            %>
        </td>
    </tr>
    <tr>
        <td colspan="2" align="center">
            <input type="submit" class="save" value="" alt="" />
            <input type="button" class="cancel" value="" alt="" onclick="JS_LIB.redirect('/Administration/Partner/Index')" />
        </td>
    </tr>
</table>
